package io2;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * 缓冲字符流--最常用的读写字符串的流
 * 是一对高级流,并且是字符流
 * 内部维护一个默认8KB(8192)长度的char数组;
 * BufferedWriter和BufferedReader
 *
 * PrintWriter:按行写入数据
 */
public class BWDemo {
    public static void main(String[] args) throws IOException {
        //自动换行,printWriter里面封装了bufferedWriter-outputStreamWriter-fileOutputStream
        PrintWriter pw = new PrintWriter("pw.txt");
        pw.println("天青色等烟雨");
        pw.println(",而我在等你");
        System.out.println("写出完毕");
        pw.close();

        /*
        FileOutputStream fos = new FileOutputStream("pw.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw)//可以实现换行输出
        bw.write("天青色等烟雨");
        bw.write(",而我在等你");
        System.out.println("写出完毕");
        bw.close();//先运行flush()方法,在关闭;bw.flush()也可以输出
         */
    }
}
